import { createRouter, createWebHashHistory } from 'vue-router'
import Home from '@/views/homeView/homeIndex.vue'
import Login from '@/views/loginView/loginIndex.vue'
import Second from '@/router/second.js'
const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'home',
    component: Home,
    children: Second
  },
  {
    path: '/login',
    name: 'login',
    component: Login
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach(to => {
  if (to.fullPath !== '/login') {
    const token = window.sessionStorage.getItem('token')

    if (!token) {
      router.push('/login')
    }
  }
})

export default router
